<template>
  <div class="form-container">
    <el-row :gutter="20">
      <el-col
        :lg="{ span: 10, offset: 7 }"
        :md="{ span: 20, offset: 2 }"
        :sm="{ span: 20, offset: 2 }"
        :xl="{ span: 10, offset: 7 }"
        :xs="24"
      >
        <el-steps :active="active" align-center class="steps">
          <el-step description="创建会议" title="第1步" />
          <el-step description="完善各项会议信息" title="第2步" />
          <el-step description="完成" title="第3步" />
        </el-steps>
        <el-form ref="formRef" label-width="100px" :model="form" :rules="rules">
          <el-form-item label="会议名称" prop="name">
            <el-input v-model="form.name" />
          </el-form-item>
        </el-form>
        <div class="pay-button-group">
          <el-button type="primary" @click="handleSubmit">下一步</el-button>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { defineComponent, reactive, toRefs } from 'vue'
  import { doCreate } from '@/api/metting'
  import { useRouter } from 'vue-router'
  import { useStore } from 'vuex'

  export default defineComponent({
    emits: ['change-step'],
    setup() {
      const router = useRouter()
      const store = useStore()
      const state = reactive({
        active: 3,
        formRef: null,
        form: {
          name: '',
        },
        rules: {
          name: [
            { required: true, message: '请输入会议名称', trigger: 'blur' },
          ],
        },
      })
      const handleSubmit = () => {
        state['formRef'].validate(async (valid) => {
          if (valid) {
            const { data } = await doCreate(state.form)
            store.dispatch('tabs/delVisitedRoute', router.path)
            router.push({ path: '/metting/edit', query: { id: data.id } })
            // close()
          }
        })
      }
      return {
        ...toRefs(state),
        handleSubmit,
      }
    },
  })
</script>

<style lang="scss" scoped>
  .form-container {
    .pay-button-group {
      display: block;
      margin: 20px auto;
      text-align: center;
    }
    :deep() {
      .el-steps {
        margin: $base-margin auto $base-margin * 2 auto;

        .el-step__head.is-finish {
          .el-step__icon.is-text {
            color: var(--el-color-white);
            background: var(--el-color-primary);
          }

          .el-step__line {
            height: 1px;
            background: var(--el-color-primary);
          }
        }

        .el-step__head.is-process {
          color: var(--el-color-primary);
          border-color: var(--el-color-primary);

          .el-step__icon.is-text {
            color: var(--el-color-primary);
            background: var(--el-color-primary-light-9);
            border: 1px solid;
          }

          .el-step__line {
            height: 1px;
          }
        }

        .el-step__title.is-process {
          color: var(--el-color-primary);
        }

        .el-step__description.is-process {
          color: var(--el-color-primary);
        }

        .el-step__head.is-wait {
          .el-step__icon.is-text {
            border: 1px solid;
          }

          .el-step__line {
            height: 1px;
            background: var(--el-color-primary);
          }
        }
      }
    }
  }
</style>
